﻿#pragma once


#include <QDialog>
#include <QPushButton>
#include "QListView"
#include "QStringListModel"
#include "QFileDialog"
#include "QMessageBox"
#include "QApplication"
#include "QVBoxLayout"
#include <QDesktopWidget>
#include <QLibrary>
#include <QApplication>
#include <QLabel>
#include <QComboBox>
#include "QListView"
#include "QStringListModel"
#include "QLineEdit"
#include "QSpinBox"
#include "QRadioButton"
#include <QSettings>

#include "commonfunction.h"

#include "halcon_opencv.h"

using namespace std;

#include "qt_graphics_view_image.h"
#include "qt_graphics_shape_rectangle.h"


class DetectionThreshold :public QDialog
{
public:
    QSettings* m_qsettings;
    QString m_section   = "";

    MyQGraphicsView* m_view ;

    QComboBox* m_qcombobox_rgb_hsv;
    int m_rgb_hsv = 0;





    QLabel * m_qlabel_channel1_low;
    QSpinBox * m_qspinbox_channel1_low;
    QSlider* m_qslider_channel1_low;


    QLabel * m_qlabel_channel1_high;
    QSpinBox * m_qspinbox_channel1_high;
    QSlider* m_qslider_channel1_high;

    QLabel * m_qlabel_channel2_low;
    QSpinBox * m_qspinbox_channel2_low;
    QSlider* m_qslider_channel2_low;


    QLabel * m_qlabel_channel2_high;
    QSpinBox * m_qspinbox_channel2_high;
    QSlider* m_qslider_channel2_high;




    QLabel * m_qlabel_channel3_low;
    QSpinBox * m_qspinbox_channel3_low;
    QSlider* m_qslider_channel3_low;

    QLabel * m_qlabel_channel3_high;
    QSpinBox * m_qspinbox_channel3_high;
    QSlider* m_qslider_channel3_high;

    QComboBox* m_qcombobox_no_yes_mask;
    int m_no_yes_mask = 0;




    QLabel* m_qlabel_mask_low;
    QSpinBox* m_qspinbox_mask_low;
    QSlider* m_qslider_mask_low;
    int m_mask_low;

    QLabel* m_qlabel_area_low;
    QSpinBox* m_qspinbox_area_low;
    int m_area_low=0;

    QLabel* m_qlabel_area_high;
    QSpinBox* m_qspinbox_area_high;
    int m_area_high=0;

    

    QPushButton* m_pushbutton_show_orign_image;
    QPushButton* m_pushbutton_detection;
    QPushButton* m_pushbutton_save_parameter;
    QPushButton* m_pushbutton_return;

    QLabel* m_qlabel_message;

    int m_result;

    int row1, column1, row2, column2;
    int ret, message, area_unfilled, gray_defect;

    int m_size_error_now;
    int channel1_low, channel1_high, channel2_low, channel2_high, channel3_low,channel3_high;

    HDevProcedure* m_proc_detection;
    HDevProcedureCall* m_call_detection;
    HObject  image_in,region, region_show;

    HObject  region_error;

public:
    explicit DetectionThreshold(QDialog *parent = nullptr, QSettings* qsettings = nullptr,QString section="") ;
    ~DetectionThreshold() ;
    virtual void detectionImage();
    virtual bool detection( HObject image_in, QString& message);
    virtual void draw( Mat image_in,Mat& image_out);
    virtual void loadParameter();
    virtual void saveParameter();
    virtual bool showDialog();
    bool sendPLC(const Mat image_in,QString& message);
    void getRect(int x,int y,int width,int height);
    void testImage();
};
#pragma execution_character_set("utf-8")
